/**
 * 
 */
package co.gov.medellin.sdep.sisdep.gestion.service;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import co.gov.medellin.sdep.sisdep.gestion.exception.ArticuloAreaResponsableException;
import co.gov.medellin.sdep.sisdep.gestion.exception.ArticuloAreaResponsableRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.ArticuloGrupoException;
import co.gov.medellin.sdep.sisdep.gestion.exception.ArticuloGrupoRuntimeException;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.ArticuloAreaResponsableMessageDescriptor;
import co.gov.medellin.sdep.sisdep.gestion.exception.descriptor.ArticuloGrupoMessageDescriptor;
import co.gov.medellin.sdep.sisdep.common.message.MessageDescriptorConstant;
import co.gov.medellin.sdep.sisdep.common.service.BaseService;
import co.gov.medellin.sdep.sisdep.model.ArticuloAreaResponsable;
import co.gov.medellin.sdep.sisdep.model.ArticuloGrupo;
import co.gov.medellin.sdep.sisdep.model.dao.impl.IArticuloAreaResponsableDAOT;

/**
 * @author Usuario
 *
 */
public class ArticuloAreaResponsableServiceImpl extends BaseService implements IArticuloAreaResponsableService, Serializable {

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                 init()
	//----------------------------------------------------------------------

	/**
	 * default serial version
	 */
	private static final long serialVersionUID = 1L;
	/** */
	private IArticuloAreaResponsableDAOT articuloAreaResponsableDAO;

	/**
	 * 
	 */
	public ArticuloAreaResponsableServiceImpl() {
	}

	//----------------------------------------------------------------------
	//--- propiedades y constructores                                  end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                     init()
	//----------------------------------------------------------------------

	/**
	 * 
	 */
	public void insert(ArticuloAreaResponsable articuloAreaResponsable) throws ArticuloAreaResponsableException {
		try{
			articuloAreaResponsable.setUsuarioCrea(getPrincipalUser());
			articuloAreaResponsable.setFechaCrea(new Date());
			getArticuloAreaResponsableDAO().insert(articuloAreaResponsable);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ArticuloAreaResponsableException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ArticuloAreaResponsableException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.SAVE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void update(ArticuloAreaResponsable articuloAreaResponsable) throws ArticuloAreaResponsableException {
		try{
			articuloAreaResponsable.setUsuarioModifica(getPrincipalUser());
			articuloAreaResponsable.setFechaModifica(new Date());
			getArticuloAreaResponsableDAO().update(articuloAreaResponsable);
		}catch (Exception e) {
			Object [] infoError = {
			};
			if(e.getCause().toString().indexOf("UNIQUE KEY") >= 0){
				throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.UK_VIOLATION), infoError, e);
			}else{
				throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.UPDATE), infoError, e);
			}
		}
	}

	/**
	 * 
	 */
	public final void delete(ArticuloAreaResponsable articuloAreaResponsable) throws ArticuloAreaResponsableException {
		try {
			articuloAreaResponsable.setUsuarioModifica(getPrincipalUser());
			articuloAreaResponsable.setFechaModifica(new Date());
			getArticuloAreaResponsableDAO().delete(articuloAreaResponsable);
		}catch (Exception e) {
			Object [] infoError = {
			};
			throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.DELETE), infoError, e);
		}
	}

	/**
	 * @return 
	 * 
	 */
	public final List load(int start,int max, ArticuloAreaResponsable articuloAreaResponsable) throws ArticuloAreaResponsableException {
		try{
			//return getArticuloAreaResponsableDAO().getAllArticuloAreaResponsablePaginated(start, max, criteria);
			return getArticuloAreaResponsableDAO().load(articuloAreaResponsable);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final ArticuloAreaResponsable get(long id) throws ArticuloAreaResponsableException {
		try{
			return getArticuloAreaResponsableDAO().findByPrimaryKey(id);
		}catch (Exception e) {
			Object [] infoError = {new Long(id)};
			throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.GET), infoError, e);
		}
	}

	/**
	 * 
	 */
	public final List loadMasterListItems() throws ArticuloAreaResponsableException {
		try{
			ArticuloAreaResponsable articuloAreaResponsable = new ArticuloAreaResponsable();
			articuloAreaResponsable.setEstado("ACTIVO");
			return getArticuloAreaResponsableDAO().loadMasterListItems(articuloAreaResponsable);
		}catch (Exception e) {
			Object [] infoError = null;
			throw new ArticuloAreaResponsableRuntimeException(new ArticuloAreaResponsableMessageDescriptor(MessageDescriptorConstant.RETRIEVE), infoError, e);
		}
	}

	//----------------------------------------------------------------------
	//--- implementacion de metodos para acciones                      end()
	//----------------------------------------------------------------------

	//----------------------------------------------------------------------
	//--- getters and setters                                         init()
	//----------------------------------------------------------------------

	/**
	 * @author Usuario
	 *
	 */
	public IArticuloAreaResponsableDAOT getArticuloAreaResponsableDAO() {
		return articuloAreaResponsableDAO;
	}

	/**
	 * @author Usuario
	 *
	 */
	public void setArticuloAreaResponsableDAO(IArticuloAreaResponsableDAOT articuloAreaResponsableDAO) {
		this.articuloAreaResponsableDAO = articuloAreaResponsableDAO;
	}

	//----------------------------------------------------------------------
	//--- getters and setters                                          end()
	//----------------------------------------------------------------------

}
